/**
 * Created by lx on 2017/5/16.
 */
/**
 * Created by lx on 2017/4/5.
 */
angular.module('app.module.management', [
])
    .config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
        $stateProvider
            .state('verification.addverification', {
                url : '/management/addverification',
                templateUrl : template_viewurl+"/management/addverification.html",
                controller : 'AddverificationController'
            })
            .state('verification.verificationlist', {
                url : '/management/verificationlist',
                resolve:{
                    checkuser:['ManagementService',function(ManagementService){
                        var myshopid="524545";
                        return ManagementService.getshop(myshopid).$promise;
                    }]
                },
                templateUrl : template_viewurl+"/management/list.html",
                controller : 'VerificationlistController'
            })
    }])
    .controller('VerificationlistController', ['$scope','$state','$interval', 'ManagementService','checkuser', function($scope,$state,$interval,ManagementService,checkuser) {
        $scope.shops=checkuser;
        var myshopid="977534855";
        $scope.orderbystatus=function(tips){
            $scope.shops=[];
            switch(tips){
                case 1:
                    ManagementService.getshop(myshopid).$promise.then(function(shop){
                        for(var i=0;i<shop.length;i++){
                            if(shop[i].status==1){
                                $scope.shops.push(shop[i]);
                            }
                        }
                    },function(error){
                        console.log("error:",error)
                    })
                    break;
                case 2:
                    ManagementService.getshop(myshopid).$promise.then(function(shop){
                        $scope.shops=[];
                        for(var i=0;i<shop.length;i++){
                            if(shop[i].status==0){
                                $scope.shops.push(shop[i]);
                            }
                        }
                    },function(error){
                        console.log("error:",error)
                    })
                    break;
                default:
                    ManagementService.getshop(myshopid).$promise.then(function(shop){
                        $scope.shops=shop;
                    },function(error){
                        console.log("error:",error)
                    })
                    break;
            }
        }
        $scope.modifystatus=function(shop,$event){
            if(shop.status==0){
                shop.status=1;
                ManagementService.modifshop(shop.verificationid,shop,function(success){
                    $event.target.setAttribute("disabled", "disabled");
                },function(error){
                      console.log("error:",error)
                })
            }else{
                $event.target.setAttribute("disabled", "disabled");
            }
        }
            $scope.remove=function(verid){
                ManagementService.deleteshop(verid,function(success){
                    ManagementService.getshop(myshopid).$promise.then(function(shop){
                        $scope.shops=shop;
                    },function(error){
                        console.log("error:",error)
                    })
                 },function(error){
                 console.log("error:",error)

                 })
            }

        }])
    .controller('AddverificationController', ['$scope','$state', function($scope,$state) {


    }])
